package com.itplh.modules.shirojwt.controller;

import com.itplh.modules.shirojwt.common.RestResponse;
import com.itplh.modules.shirojwt.constants.OAuthConstant.Permissions;
import com.itplh.modules.shirojwt.constants.OAuthConstant.Roles;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: tanpeng
 * @Date: 2019-07-10 22:34
 * @Version: V1.0
 */
@RestController
@RequestMapping(value = "/shirojwt")
public class RestApiController {

  @PostMapping("/add")
  @RequiresPermissions(Permissions.INSERT)
  public RestResponse<String> add() {
    return RestResponse.OK("add success");
  }

  @GetMapping("/find")
  @RequiresPermissions(Permissions.SELECT)
  public RestResponse<String> find() {
    return RestResponse.OK("find success");
  }

  @PutMapping("/update")
  @RequiresPermissions(Permissions.UPDATE)
  public RestResponse<String> update() {
    return RestResponse.OK("update success");
  }

  @DeleteMapping("/delete")
  @RequiresPermissions(Permissions.DELETE)
  public RestResponse<String> delete() {
    return RestResponse.OK("delete success");
  }

  @GetMapping("/find/_user")
  @RequiresRoles(Roles.USER)
  public RestResponse<String> user() {
    return RestResponse.OK("user success");
  }

  @GetMapping("/find/_admin")
  @RequiresRoles(Roles.ADMIN)
  public RestResponse<String> admin() {
    return RestResponse.OK("admin success");
  }

  @GetMapping("/list")
  @RequiresRoles(Roles.USER)
  @RequiresPermissions(Permissions.SELECT)
  public RestResponse<String> list() {
    return RestResponse.OK("list success");
  }

  @GetMapping("/access")
  public RestResponse<String> test() {
    return RestResponse.OK("access success");
  }

}
